package Logic;

import microgame.toolset.datatable.Row;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;

public class PropStubManager {
    private Hashtable<Integer, PropStubGroup> propStubGroupMap = new Hashtable<>();
    private Match match;
    private int currentPropId;

    public PropStubManager(Match match) {
        this.match = match;
        this.currentPropId = 0;
        ArrayList<Row> allPropTemplates = PropDataTemplate.Instance().GetAllPropTemplate();
        for (int i = 0; i < allPropTemplates.size(); ++i) {
            int templateId = allPropTemplates.get(i).GetInteger("id");
            propStubGroupMap.put(templateId, new PropStubGroup(templateId, match));
        }
    }

    //这里的参数单位是秒
    public void Tick(float deltaTime) {
        for (Map.Entry<Integer, PropStubGroup> entry: propStubGroupMap.entrySet()) {
            entry.getValue().Tick(deltaTime);
        }
    }

    public Match GetMatch() {
        return match;
    }

    public int NextPropId() {
        return currentPropId++;
    }

    public void PropStubCollision(int clientId, int templateId, int propId) {
        propStubGroupMap.get(templateId).PropStubCollision(clientId, propId);
    }
}
